package com.yl.ydk.ui.activity

import android.content.Intent
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.yl.ydk.R
import com.yl.ydk.base.BaseActivity
import com.yl.ydk.presenter.contract.SiteArticleActivityContract
import com.yl.ydk.presenter.impl.SiteArticleActivityImpl
import com.blankj.utilcode.utils.ToastUtils
import kotlinx.android.synthetic.main.activity_site_article.*
import kotlinx.android.synthetic.main.roob_bar.*

class SiteArticleActivity : BaseActivity(), SiteArticleActivityContract.View, View.OnClickListener {


    private val mPresenter = SiteArticleActivityImpl()

    override fun getLayoutId(): Int = R.layout.activity_site_article

    override fun attachView() {
        mPresenter.attachView(this)
    }

    override fun detachView() {
        mPresenter.detachView()
    }

    override fun initView() {

        tvTitle.text = "急救手册"
        rlSearch.visibility = View.VISIBLE
        rlBack.setOnClickListener(this)
        rlSearch.setOnClickListener(this)
        rlSearch1.setOnClickListener(this)
        rlSearch2.setOnClickListener(this)
        rlSearch3.setOnClickListener(this)

        mPresenter.getSiteAricle(this)

    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.rlBack -> {
                finish()
            }
            R.id.rlSearch -> {
                startActivityIn(Intent(this, SiteArticleSearchActivity::class.java), this)
            }
            R.id.rlSearch1 -> {
                val intent = Intent(this, SiteArticleSearchActivity::class.java)
                intent.putExtra("data", tvSearch1.text.toString().trim())
                startActivityIn(intent, this)
            }
            R.id.rlSearch2 -> {
                val intent = Intent(this, SiteArticleSearchActivity::class.java)
                intent.putExtra("data", tvSearch2.text.toString().trim())
                startActivityIn(intent, this)
            }
            R.id.rlSearch3 -> {
                val intent = Intent(this, SiteArticleSearchActivity::class.java)
                intent.putExtra("data", tvSearch3.text.toString().trim())
                startActivityIn(intent, this)
            }
        }
    }

    override fun getRecyclerView(): RecyclerView? = rvSiteArticle

    override fun getActivity(): SiteArticleActivity = this

    override fun showError(message: String?) {
        ToastUtils.showLongToastSafe(message)
    }

}